import { useEffect } from "react";
import { Navigate } from "react-router-dom";
import { getQueryString } from '@commonMethod'
import { message } from "antd"


import Main from "./main";
import MapMain from "./mapMain";

import { session } from "@core";

const mapError = (event)=>{
    if ((event instanceof ErrorEvent)) return
    // console.log(event);
    const src = event.target.src
    if (src.includes('baidu.com')) {
      message.error('地图部分资源加载错误，请检查网络或者刷新页面');
    }
  }
window.addEventListener('error', mapError, true);

function AuthLogin(){
    const partnerCode = getQueryString('partnerCode')
    const encryptData = getQueryString('encryptData')

    useEffect(() => {
        return () => {
            window.removeEventListener('error', mapError, true);
        }
    },[])

    if (encryptData && partnerCode) {
        return <MapMain />
    }
    const isToken= session.get('token');
    if(isToken){
        return <Main />
    }
    return <Navigate to="/login"></Navigate>
}
export default AuthLogin;